package fr.upmc.tep.lambda.evaluation.types;

/**
 * This class represents a node which contains an application. An application
 * has two members which can be other applications, abstractions or
 * variables.
 * 
 * @author Fabrice Reynaud, Yihan Wang
 *
 */
public class LApplicationNode extends LNode{

	private LNode left;
	private LNode right;
	
	public LApplicationNode(LNode left, LNode right, LNode parent) {
		super(parent);
		this.left = left;
		this.right = right;
	}

	public LNode getLeft() {
		return left;
	}

	public void setLeft(LNode left) {
		this.left = left;
	}

	public LNode getRight() {
		return right;
	}

	public void setRight(LNode right) {
		this.right = right;
	}

	/**
	 * There is two cases to write an Application back to a String. If the right
	 * member of an Application is also an Application, then we use parenthesis
	 * to surround it. Else we just write it after the left member.
	 */
	public String toLambdaExpression() {
		String result = "";		
		if(right.getClass().getSimpleName().equals("LApplicationNode"))
			result += left.toLambdaExpression() + "(" + right.toLambdaExpression() + ")";
		else result += left.toLambdaExpression() + right.toLambdaExpression();
		return result;
	}
}